import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class FindRepeatedDnaSequences {

    public List<String> findRepeatedDnaSequences(String s) {
        List<String> ans = new ArrayList<>();
        HashMap<String, Integer> maps = new HashMap<>();
        for (int i = 0; i < s.length() - 9; i++) {
            String temp = s.substring(i, i + 10);
            Integer count = maps.getOrDefault(temp, 0);
            if (count == 0) {
                maps.put(temp, 1);
            } else if (count == 1) {
                maps.put(temp, 2);
                ans.add(temp);
            }
        }
        return ans;
    }
}
